package top.ijiujiu.service.impl;

import com.baomidou.mybatisplus.core.toolkit.Wrappers;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import org.springframework.security.core.userdetails.UserDetails;
import org.springframework.security.core.userdetails.UserDetailsService;
import org.springframework.security.core.userdetails.UsernameNotFoundException;
import org.springframework.stereotype.Service;
import org.springframework.util.ObjectUtils;
import top.ijiujiu.entity.SysUser;
import top.ijiujiu.mapper.SysUserMapper;
import top.ijiujiu.service.ISysUserService;

/**
 * 用户表 服务实现类
 *
 * @Author 神秘的黄瓜
 * @Version 1.0
 * @Date 2020-04-01
 */
@Service
public class SysUserServiceImpl extends ServiceImpl<SysUserMapper, SysUser> implements ISysUserService, UserDetailsService {

    @Override
    public UserDetails loadUserByUsername(String account) throws UsernameNotFoundException {
        SysUser user = this.baseMapper.selectOne(Wrappers.<SysUser>lambdaQuery().eq(SysUser::getAccount, account));
        if (ObjectUtils.isEmpty(user)){
            throw new UsernameNotFoundException("找不到指定的用户信息!");
        }
        return user;
    }
}
